import { ApiProperty } from '@nestjs/swagger';
import * as moment from 'moment'; // 修改这里
import {
  BeforeInsert,
  BeforeUpdate,
  Column,
  CreateDateColumn,
  Timestamp,
  UpdateDateColumn,
} from 'typeorm';
// @ts-ignore
export abstract class BaseEntity {
  @Column({ name: 'createdTime', nullable: true })
  @ApiProperty({
    required: false,
  })
  createdTime: string;

  @Column({ name: 'updateTime', nullable: true })
  @ApiProperty({
    required: false,
  })
  updateTime: string;

  // @ts-ignore
  @BeforeInsert()
  updateTimestampsOnInsert() {
    // @ts-ignore
    this.createdTime = moment().format('YYYY-MM-DD HH:mm:ss');
    // @ts-ignore
    this.updateTime = moment().format('YYYY-MM-DD HH:mm:ss');
  }
  // @ts-ignore
  @BeforeUpdate()
  updateTimestampsOnUpdate() {
    // @ts-ignore
    this.updateTime = moment().format('YYYY-MM-DD HH:mm:ss');
  }
}
